<template>
  <div>
    <iep-page-header title="商品审核" :backOption="backOption"></iep-page-header>
    <OperationContainer class="opera" style="margin-bottom: 10px">
      <div slot="right">
        <searchForm  @searchPage="searchPage"></searchForm>
      </div>
    </OperationContainer>
    <iep-table
      :isLoadTable="isLoadTable"
      :pagination="pagination"
      :dictsMap="dictsMap"
      :columnsMap="columnsMap"
      :pagedTable="pagedTable"
      @pagination-size-change="handlePaginationSizeChange"
      @pagination-current-change="handlePaginationCurrentChange"
    >
      <el-table-column prop="operation" label="操作" width="220" align="center">
        <template slot-scope="scope">
          <operation-wrapper>
            <iep-button type="warning" plain @click="handleDetail(scope.row)">详情</iep-button>
            <iep-button type="warning" plain @click="handleExamine(scope.row, '通过', 2)" v-if="scope.row.certificationStatus === '1'">通过</iep-button>
            <iep-button type="warning" plain @click="handleRefuce(scope.row, '驳回', 3)" v-if="scope.row.certificationStatus === '1'">驳回</iep-button>
          </operation-wrapper>
        </template>
      </el-table-column>
    </iep-table>
    <!-- <dialog-system ref="dialogSystem"></dialog-system> -->
  </div>
</template>

<script>
import { getCertifyPage, certifyShop } from '@/api/product'
import { mapGetters } from 'vuex'
import Mixin from '@/mixins/mixins'
import operationMixins from '@/mixins/operationMixins'
import { columnsMap } from '../options'
import searchForm from '../searchForm'
export default {
  components: { searchForm },
  mixins: [operationMixins, Mixin],
  data () {
    return {
      backOption: {
        isBack: false
      },
      checkAll: false,
      columnsMap
    }
  },
  computed: {
    ...mapGetters(['dictGroup', 'dictObject']),
    noPlanTypesMap () {
      return []
    },
    isAll: {
      get: function () {
        return this.checkAll ? '1' : '0'
      },
      set: function (value) {
        if (value === '1') {
          this.checkAll = true
        } else {
          this.checkAll = false
        }
      }
    },
    cpms_products_view () {
      return true
    },
    cpms_products_all_view () {
      return true
    },
    ...mapGetters(['userInfo']),
    dictsMap () {
      return {
        type: this.dictObject['product_type'],
        certificationStatus: this.dictObject['examine_status']
      }
    }
  },
  mounted () {
    this.isAll = this.$route.query.isAll
  },
  methods: {
    handleDetail (row) {
      this.$router.push(`/product-release-detail/${row.productId}`)
    },
    handleSearch (form) {
      this.$refs['CrudTable'].searchPage(form)
    },
    loadPage (params = this.searchForm) {
      this.loadTable(params, getCertifyPage)
    },
    handleExamine (row, tip, state) {
      this.$confirm(`是否${tip}审核`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http({
          url: this.$http.adornUrl(certifyShop().url),
          method: certifyShop().method,
          data: {
            id: row.productId,
            status: state
          }
        }).then(({ data }) => {
          if (data) {
            this.$message({
              type: 'success',
              message: `${tip}成功`
            })
            this.loadPage()
          }
        })
      }).catch(() => { })
    },
    handleRefuce (row) {
      this.$prompt('请输入驳回理由', '驳回', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPattern: /\S/,
        inputErrorMessage: '必填'
      }).then(({ value }) => {
        this.$http({
          url: this.$http.adornUrl(certifyShop().url),
          method: certifyShop().method,
          data: {
            id: row.productId,
            status: 3,
            remarks: value
          }
        }).then(({ data }) => {
          if (data) {
            this.$message({
              type: 'success',
              message: '驳回成功'
            })
            this.loadPage()
          }
        })
      }).catch(() => {})
    }
  },
  created () {
    this.loadPage()
  }
}
</script>
